<%--
  Created by IntelliJ IDEA.
  User: windows
  Date: 2021/10/29
  Time: 10:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.js"></script>
</head>
<body>

<div style="border-radius: 5px;margin-top: 100px;margin-left: 200px;margin-right: 200px">
    <form class="layui-form layui-form-pane" action="" id="form-search">
        <fieldset class="table-search-fieldset">
            <legend>搜索条件</legend>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">姓名:</label>
                    <div class="layui-input-inline" style="width: 150px;">
                        <input type="text" name="name" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">日期:</label>
                    <div class="layui-input-inline" style="width: 200px;">
                        <input id="startDate" type="text" name="startDate" placeholder="起始日期" autocomplete="off" class="layui-input date">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <input id="endDate" type="text" name="endDate" placeholder="终止日期" autocomplete="off"
                               class="layui-input date">
                    </div>

                </div>
                <button  id="btn-search" lay-submit lay-filter="btn-search-filter" type="button" class="layui-btn layui-btn-radius layui-btn-normal">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button  id="btn-reset" type="reset" class="layui-btn layui-btn-radius layui-btn-primary">
                    <i class="layui-icon layui-icon-fonts-clear"></i>
                    清空条件
                </button>
            </div>
        </fieldset>
    </form>
    <table id="demo" lay-filter="table-pic-filter"></table>
</div>

<script type="text/html" id="col-pic-toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
</script>
<script>

    layui.use(['laydate', 'table', 'form'], function () {
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;

        //表格头部工具栏事件监听
        form.on('submit(btn-search-filter)', function(data){
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

            table.reload('demo', {
                where: { //设定异步数据接口的额外参数，任意设
                    name: data.field.name,
                    startDate: data.field.startDate,
                    endDate: data.field.endDate
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        laydate.render({
            elem: '.date' //指定元素
        });

        table.render({
            elem: '#demo'
            , height: 312
            , url: '/data.jsp' //数据接口
            , page: false //关闭分页
            , cols: [[ //表头
                {field: 'id', title: 'id', width: 100, sort: true, fixed: 'left'}
                , {field: 'username', title: 'username', width: 200}
                , {field: 'birthday', title: 'birthday', width: 200}
                , {title: '操作', align: 'center', toolbar: '#col-pic-toolbar'}
            ]]
        });

        table.on('tool(table-pic-filter)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;
            if (layEvent === 'look') {
                console.log(data.name)
                console.log("list id: " + data.id);
                sessionStorage.setItem("id", data.id)
                let url = '/transfer.jsp'
                layer.open({
                    type: 2,
                    title: "查看图片",
                    area: ['60%', '60%'],
                    shadeClose: true,
                    content: url
                });
            }
        });
    });

</script>
</body>
</html>


